package com.jinghong.registerlogin.aop;

import com.jinghong.registerlogin.utils.ThreadLocalUtil;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * ClassName:isAdminAspect
 * Package:com.jinghong.registerlogin.aop
 * Description:
 *
 * @Author: 寻月君子
 * @CreatTime:2024/6/1 13:59
 * Version:1.0
 */
@Slf4j
@Component
@Aspect
public class IsAdminAspect {


    @Pointcut("execution(* com.jinghong.registerlogin.controller.AdminController.*(..))")
    private void pt(){}


    @Before("pt()")
    public void judgeAdmin() throws Exception {
        Map<String,Object> map = ThreadLocalUtil.get();
        Integer isAdmin = (Integer) map.get("isAdmin");
        if (isAdmin != 0){
            throw new Exception("没有管理员权限");
        }

    }


}
